/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JFrameSplash.java
 *
 * Created on 23/03/2011, 01:22:53 PM
 */

package rutascoronasa.resources;

import Modelo.ConexionModelo;
import Vista.MenuPrincipal;
import com.mysql.jdbc.Connection;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author SAW
 */
public class Splash extends javax.swing.JFrame implements Runnable{
    Thread t;    
    ConexionModelo conexi=new ConexionModelo();

    /** Creates new form JFrameSplash */
    public Splash(){
        initComponents();
        //this.setLocationRelativeTo(null);

    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(51, 51, 0));
        setUndecorated(true);

        jLabel1.setBackground(new java.awt.Color(255, 0, 51));
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/rutascoronasa/resources/Imagenes/SplashCorona.gif"))); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 453, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void run(){

        try {
            this.setLocationRelativeTo(null);
            this.setVisible(true);
            t.sleep(5000);

            try {//verifico conexion
                conexi.connect();
                if( !conexi.isConnect() ){
                   while(!conexi.isConnect()){
                        conexi.connect();
                   }
                }
            } catch (SQLException ex) {
                Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
            }

            this.dispose();
            try {
          //      JFrameMenuPrincipal inicio = new JFrameMenuPrincipal();
                MenuPrincipal inicio;
                inicio = new MenuPrincipal();
                inicio.setVisible(true);
            } catch (SQLException ex) {
                    Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        } catch (InterruptedException ex) {
            Logger.getLogger(Splash.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables

}
